<?php

/**
 * @author quang
 * @copyright 2012
 */

require_once('/includes/general.php');

class UserService{
    public function add($aVals){
        tep_db_checkDb() or die('Không thể kết nối cơ sở dữ liệu');
        
        $sql = "insert into tbl_khach_hang(ho_ten, ten_dang_nhap, mat_khau, email, dia_chi, so_dien_thoai) 
                    values('".$aVals['realname']."', '".$aVals['username']."', '". md5($aVals['password'])."', '". $aVals['email']
                    . "', '". $aVals['address']."', '".$aVals['phone']."')";
        tep_db_query($sql);
        return tep_db_insert_id();
    }
    
    public function get($id){
        $sql = "select * from tbl_khach_hang where id= $id";
        $query = tep_db_query($sql);
        return tep_db_fetch_array($query);
    }
    
    public function checkLogin($username, $password){
        tep_db_checkDb() or die('Connect failed');
        $sql = "select * from tbl_khach_hang where ten_dang_nhap='".$username."' and mat_khau='".md5($password)."'";
        $query = tep_db_query($sql);
        return tep_db_fetch_array($query); 
    }
}

?>